/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('ei-iot-openapi', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model App {
  appKey?: string(name='AppKey', description='appKey'),
  requestId?: string(name='RequestId', description='requestId'),
  requestTs?: long(name='RequestTs', description='请求时间戳(ms)'),
  sign?: string(name='Sign', description='签名'),
  signType?: string(name='SignType', description='签名类型'),
}

model Response {
  model?: string(name='Model', description='Model'),
  msgCode?: string(name='MsgCode', description='MsgCode'),
  msgInfo?: string(name='MsgInfo', description='MsgInfo'),
  requestId?: string(name='RequestId', description='请求Id'),
  success?: boolean(name='Success', description='Success'),
}

model Tenant {
  tenantId?: long(name='TenantId', description='租户ID'),
}

model BindDeviceRequest {
  app?: App(name='App'),
  bizRequest?: {
    deviceCode?: string(name='DeviceCode'),
    spaceUnitId?: long(name='SpaceUnitId'),
  }(name='BizRequest'),
  tenant?: Tenant(name='Tenant'),
}

model BindDeviceResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function bindDeviceWithOptions(request: BindDeviceRequest, runtime: Util.RuntimeOptions): BindDeviceResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.bizRequest)) {
    bodyFlat['BizRequest'] = request.bizRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'BindDevice',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function bindDevice(request: BindDeviceRequest): BindDeviceResponse {
  var runtime = new Util.RuntimeOptions{};
  return bindDeviceWithOptions(request, runtime);
}

model BindDeviceOwnerByOuterIdRequest {
  app?: App(name='App', description='App验权信息'),
  deviceModel?: string(name='DeviceModel', description='设备型号'),
  outerDeviceId?: string(name='OuterDeviceId', description='设备外部ID'),
  ownerId?: string(name='OwnerId', description='设备ownerId'),
}

model BindDeviceOwnerByOuterIdResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function bindDeviceOwnerByOuterIdWithOptions(request: BindDeviceOwnerByOuterIdRequest, runtime: Util.RuntimeOptions): BindDeviceOwnerByOuterIdResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.deviceModel)) {
    body['DeviceModel'] = request.deviceModel;
  }
  if (!Util.isUnset(request.outerDeviceId)) {
    body['OuterDeviceId'] = request.outerDeviceId;
  }
  if (!Util.isUnset(request.ownerId)) {
    body['OwnerId'] = request.ownerId;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'BindDeviceOwnerByOuterId',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function bindDeviceOwnerByOuterId(request: BindDeviceOwnerByOuterIdRequest): BindDeviceOwnerByOuterIdResponse {
  var runtime = new Util.RuntimeOptions{};
  return bindDeviceOwnerByOuterIdWithOptions(request, runtime);
}

model GetCurrentCommandEventLogRequest {
  app?: App(name='App', description='app验权信息'),
  bizRequest?: {
    deviceCode?: string(name='DeviceCode', description='设备code'),
    type?: string(name='Type', description='命令/事件类型'),
  }(name='BizRequest', description='业务信息'),
  tenant?: Tenant(name='Tenant', description='租户信息'),
}

model GetCurrentCommandEventLogResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function getCurrentCommandEventLogWithOptions(request: GetCurrentCommandEventLogRequest, runtime: Util.RuntimeOptions): GetCurrentCommandEventLogResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.bizRequest)) {
    bodyFlat['BizRequest'] = request.bizRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetCurrentCommandEventLog',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getCurrentCommandEventLog(request: GetCurrentCommandEventLogRequest): GetCurrentCommandEventLogResponse {
  var runtime = new Util.RuntimeOptions{};
  return getCurrentCommandEventLogWithOptions(request, runtime);
}

model GetTemplatePropertyValueByCodeRequest {
  app?: App(name='App', description='app验权信息'),
  deviceCode?: string(name='DeviceCode', description='设备编码'),
  tenant?: Tenant(name='Tenant', description='租户信息'),
}

model GetTemplatePropertyValueByCodeResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function getTemplatePropertyValueByCodeWithOptions(request: GetTemplatePropertyValueByCodeRequest, runtime: Util.RuntimeOptions): GetTemplatePropertyValueByCodeResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.deviceCode)) {
    body['DeviceCode'] = request.deviceCode;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetTemplatePropertyValueByCode',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getTemplatePropertyValueByCode(request: GetTemplatePropertyValueByCodeRequest): GetTemplatePropertyValueByCodeResponse {
  var runtime = new Util.RuntimeOptions{};
  return getTemplatePropertyValueByCodeWithOptions(request, runtime);
}

model PageDeviceInfoListRequest {
  app?: App(name='App'),
  bizRequest?: {
    activeStatus?: long(name='ActiveStatus'),
    currentPage?: long(name='CurrentPage'),
    deviceCode?: string(name='DeviceCode'),
    deviceIp?: string(name='DeviceIp'),
    deviceMac?: string(name='DeviceMac'),
    deviceName?: string(name='DeviceName'),
    deviceType?: string(name='DeviceType'),
    keyword?: string(name='Keyword'),
    lastUpdateEnd?: long(name='LastUpdateEnd'),
    lastUpdateStart?: long(name='LastUpdateStart'),
    modelCode?: string(name='ModelCode'),
    pageSize?: long(name='PageSize'),
    runStatus?: string(name='RunStatus'),
    seriesNum?: string(name='SeriesNum'),
    spaceCode?: string(name='SpaceCode'),
    spaceId?: long(name='SpaceId'),
  }(name='BizRequest'),
  tenant?: Tenant(name='Tenant'),
}

model PageDeviceInfoListResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function pageDeviceInfoListWithOptions(request: PageDeviceInfoListRequest, runtime: Util.RuntimeOptions): PageDeviceInfoListResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.bizRequest)) {
    bodyFlat['BizRequest'] = request.bizRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'PageDeviceInfoList',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function pageDeviceInfoList(request: PageDeviceInfoListRequest): PageDeviceInfoListResponse {
  var runtime = new Util.RuntimeOptions{};
  return pageDeviceInfoListWithOptions(request, runtime);
}

model SyncDevicePropertyRequest {
  app?: App(name='App', description='app验权信息'),
  deviceDataPushRequest?: {
    deviceCode?: string(name='DeviceCode', description='设备编码'),
    devicePropertyMap?: map[string]any(name='DevicePropertyMap', description='设备模板中设备自定义属性值'),
    predefinePropertyMap?: map[string]any(name='PredefinePropertyMap', description='设备模板中设备预定义扩展属性值'),
    protocolPropertyMap?: map[string]any(name='ProtocolPropertyMap', description='设备协议中的设备协议属性值'),
  }(name='DeviceDataPushRequest'),
  tenant?: Tenant(name='Tenant', description='租户信息'),
}

model SyncDevicePropertyResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function syncDevicePropertyWithOptions(request: SyncDevicePropertyRequest, runtime: Util.RuntimeOptions): SyncDevicePropertyResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.deviceDataPushRequest)) {
    bodyFlat['DeviceDataPushRequest'] = request.deviceDataPushRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SyncDeviceProperty',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function syncDeviceProperty(request: SyncDevicePropertyRequest): SyncDevicePropertyResponse {
  var runtime = new Util.RuntimeOptions{};
  return syncDevicePropertyWithOptions(request, runtime);
}

model UnRegisterDeviceRequest {
  app?: App(name='App'),
  deviceCode?: string(name='DeviceCode'),
  modelCode?: string(name='ModelCode'),
  outerDeviceId?: string(name='OuterDeviceId'),
}

model UnRegisterDeviceResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function unRegisterDeviceWithOptions(request: UnRegisterDeviceRequest, runtime: Util.RuntimeOptions): UnRegisterDeviceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.deviceCode)) {
    query['DeviceCode'] = request.deviceCode;
  }
  if (!Util.isUnset(request.modelCode)) {
    query['ModelCode'] = request.modelCode;
  }
  if (!Util.isUnset(request.outerDeviceId)) {
    query['OuterDeviceId'] = request.outerDeviceId;
  }
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UnRegisterDevice',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function unRegisterDevice(request: UnRegisterDeviceRequest): UnRegisterDeviceResponse {
  var runtime = new Util.RuntimeOptions{};
  return unRegisterDeviceWithOptions(request, runtime);
}

model UpdateDeviceRequest {
  app?: App(name='App', description='App校验信息'),
  deviceUpdateRequest?: {
    activeStatus?: string(name='ActiveStatus', description='激活状态 int 1表示激活0表示失活'),
    appVersion?: string(name='AppVersion', description='应用版本号'),
    deviceCode?: string(name='DeviceCode', description='设备编码'),
    deviceIp?: string(name='DeviceIp', description='设备IP'),
    deviceName?: string(name='DeviceName', description='设备名称'),
    ownerId?: string(name='OwnerId', description='设备拥有者'),
    romVersion?: string(name='RomVersion', description='rom版本号'),
  }(name='DeviceUpdateRequest', description='设备更新信息'),
  tenant?: Tenant(name='Tenant', description='租户信息'),
}

model UpdateDeviceResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function updateDeviceWithOptions(request: UpdateDeviceRequest, runtime: Util.RuntimeOptions): UpdateDeviceResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.deviceUpdateRequest)) {
    bodyFlat['DeviceUpdateRequest'] = request.deviceUpdateRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UpdateDevice',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateDevice(request: UpdateDeviceRequest): UpdateDeviceResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateDeviceWithOptions(request, runtime);
}

model UpdateSpaceUnitRequest {
  app?: App(name='App'),
  bizRequest?: {
    regionCode?: string(name='RegionCode'),
    regionName?: string(name='RegionName'),
    typeCode?: string(name='TypeCode'),
    typeName?: string(name='TypeName'),
    unitId?: string(name='UnitId'),
    unitName?: string(name='UnitName'),
  }(name='BizRequest'),
  tenant?: Tenant(name='Tenant'),
}

model UpdateSpaceUnitResponse = {
  headers: map[string]string(name='headers'),
  body: Response  
}

async function updateSpaceUnitWithOptions(request: UpdateSpaceUnitRequest, runtime: Util.RuntimeOptions): UpdateSpaceUnitResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  var bodyFlat : map[string]any= {};
  if (!Util.isUnset(request.app)) {
    bodyFlat['App'] = request.app;
  }
  if (!Util.isUnset(request.bizRequest)) {
    bodyFlat['BizRequest'] = request.bizRequest;
  }
  if (!Util.isUnset(request.tenant)) {
    bodyFlat['Tenant'] = request.tenant;
  }
  body = {
    ...body,
    ...OpenApiUtil.query(bodyFlat),
  };

  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'UpdateSpaceUnit',
    version = '2021-11-04',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function updateSpaceUnit(request: UpdateSpaceUnitRequest): UpdateSpaceUnitResponse {
  var runtime = new Util.RuntimeOptions{};
  return updateSpaceUnitWithOptions(request, runtime);
}

